package com.bing.bingPro.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bing.bingPro.controller.dto.TFiveOrderTypeDto;
import com.bing.bingPro.controller.vo.TLstfOrderVo;
import com.bing.bingPro.entity.TLstfOrder;
import com.bing.bingPro.mapper.TLstfOrderMapper;
import com.bing.bingPro.service.TLstfOrderService;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author qilong
 * @description 针对表【t_lstf_order】的数据库操作Service实现
 * @createDate
 */
@Service
public class TLstfOrderServiceImpl extends ServiceImpl<TLstfOrderMapper, TLstfOrder>
        implements TLstfOrderService {

    @Override
    public List<TLstfOrderVo> lowFullnessList(TFiveOrderTypeDto tOrderYearDto) {
        Date date = Date.valueOf(tOrderYearDto.getTime());
        String provinceName = tOrderYearDto.getProvinceName();
        return baseMapper.selectList(Wrappers.lambdaQuery(TLstfOrder.class)
                        .eq(true, TLstfOrder::getDt, date)
                .like(CharSequenceUtil.isNotEmpty(provinceName), TLstfOrder::getProvinceName, "%" + provinceName + "%"))
                .stream()
                .map(tLstfOrder -> {
                    TLstfOrderVo vo = new TLstfOrderVo();
                    BeanUtil.copyProperties(tLstfOrder, vo);
                    return vo;
                })
                .collect(Collectors.toList());
    }

    @Override
    public List<TLstfOrderVo> exportLowFullness(TFiveOrderTypeDto tOrderYearDto) {
        Date date = Date.valueOf(tOrderYearDto.getTime());
        String dateString = tOrderYearDto.getTime().toString();
        return baseMapper.selectList(Wrappers.lambdaQuery(TLstfOrder.class)
                        .eq(true, TLstfOrder::getDt, date))
                .stream()
                .map(tLstfOrder -> {
                    TLstfOrderVo vo = new TLstfOrderVo();
                    BeanUtil.copyProperties(tLstfOrder, vo);
                    vo.setDt(dateString);
                    return vo;
                })
                .collect(Collectors.toList());
    }
}




